<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/10 0010
 * Time: 21:06
 */
//echo '父进程ID' . posix_getpid();
$workers = [];
for ($i = 0; $i < 6; $i++) {
    $process = new Swoole\Process(function (Swoole\Process $process) {
        //子进程空间
        //    while (true){
        //
        //    }
        // echo '' . posix_getpid().PHP_EOL;
        // echo posix_getppid().PHP_EOL;

//        echo '子进程读取:' . $process->read().PHP_EOL;
        sleep(2);
        echo '重定向标准输入输出 第二个参数 true';
//        $process->write('子进程写入');

    }, true, true);
    $pid = $process->start();
    $workers [$pid] = $process;
    $process->write('主进程写入');
    //异步监听管道当中的数据 读事件的监听 当管道可读的时候触发
    swoole_event_add($process->pipe, function ($pipe) use ($process) {
        var_dump('主进程', $process->read());
    });
}
//foreach ($workers as $index => $worker) {
//    var_dump($worker->read() . PHP_EOL);
//}